app.service('merchantsService',['$http','$q','utilService',function($http,$q,utilService){

    this.getIndustryFullName = function($scope){
        var deferred = $q.defer();
        $http.get($scope.app.domain + '/shop/get/industry/list'
        ).then(function(reslut){
                deferred.resolve(reslut.data);
            },function(e){
                deferred.reject("连接服务器出错");
            });
        return deferred.promise;
    }

    this.findById = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/info/id',
            params:{id:$scope.shopUpdateVO.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.updateSystemUserStatus = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'system/user/update/status/'+$scope.data.id,
            data:{id:$scope.data.id,status:$scope.data.status},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.updateMerchants = function($scope){
        delete $scope.shopUpdateVO.auditStatus;
        var let = $scope.shopUpdateVO.lat;
        if (let == null || let == undefined || let == '') {
            delete $scope.shopUpdateVO.lat;
        }
        var lng = $scope.shopUpdateVO.lat;
        if (lng == null || lng == undefined || lng == '') {
            delete $scope.shopUpdateVO.lng;
        }
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'shop',
            data:$scope.shopUpdateVO,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.updateMerchantsAudit = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'shop/merchants/audit',
            data: $scope.merchants,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.findByShopId = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/info/shopid/'+ $scope.shopUpdateVO.id
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }
}]);

